from 内部变量 import *
import pandas as pd

df = pd.read_excel('data.xlsx', sheet_name = '编码数据（线上和线下）')

loveScore=[]
marriageScore=[]
birthScore=[]
familyScore=[]

def addNewScore(scoreArray:list, varDict:dict) -> None:
    newScore = 0
    for question, scoreDict in varDict.items():
        newScore += scoreDict[row[question]]
    scoreArray.append(newScore)

for index, row in df.iterrows():
    addNewScore(loveScore, love)
    addNewScore(marriageScore, marriage)
    addNewScore(birthScore, birth)
    addNewScore(familyScore, family)
    print(index)

import numpy as np

loveScore=np.array(loveScore)
marriageScore=np.array(marriageScore)
birthScore=np.array(birthScore)
familyScore=np.array(familyScore)
internalVar={'love':loveScore, 'marriage':marriageScore, 'birth':birthScore, 'family':familyScore}

def basicStat(array,name:str) -> None:
    print(name,':')
    print('mean:',array.mean())
    print('std:', array.std())
    print('median:',np.median(array))

for name,array in internalVar.items():
    basicStat(array,name)

internalVar=pd.DataFrame(internalVar)
internalVar.to_csv('内部变量.csv')